#include "gd32a508.h"

#include "systick.h"

#include "main.h"
#include "bsp_can.h"
#include "bsp_gpio.h"
#include "bsp_adc.h"
#include "bsp_usart.h"

#include "app_main_can.h"
#include "app_dido.h"
#include "app_adc.h"
#include "app_rs485.h"



uint32_t g_SysHeartFlag;


static void init_bsp_object(void)
{
	init_bsp_can();
	init_bsp_dido();
	init_bsp_adc();
	init_dv_UART();

}
static void bsp_driver_init(void)
{
	dv_CAN.finit(EM_CAN_2,true);
	dv_DIDO.finit();
	dv_ADC.finit();
	dv_UART.finit(9600);
}

static void app_state_init(void)
{
	init_app_dido();
}


int main(void)
{
    uint8_t data[64] = {0,1,2,3,4,5,6,7,9,10,11};
    /* configure systick */
    systick_config();

	init_bsp_object();

	bsp_driver_init();
	
	delay_1ms(50);

	app_state_init();
	
    while(1) 
	{	
		//dv_CAN.fcommunication_loop();

		app_dido_in_check();

		app_main_can_rx_run();

		app_dido_run();

		if(g_SysHeartFlag)
		{
			g_SysHeartFlag = false;
			
			app_anlog_run();	
			app_485_run();

			app_main_can_tx_run();
			
			dv_DIDO.fledspark();
		}    
    }
}
